/****************************************************************
* created by yang.zheng on 2020-07-27 for 项目启动文件
****************************************************************/

const http = require('http');

const app = http.createServer((req,resp) => {
    console.log(req.url);
    console.log(req.method);
    console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
    HandleResult(req.url,req.method,resp)
});



/**
 * 处理接口及响应
 * @param {string} url                  请求地址
 * @param {string} method               请求方法
 * @param {serverResponse} resp         服务器响应体
 */
const HandleResult = (url,method,resp) =>{
    if (method === 'GET') {
        if(url === '/user/login') {
            resp.write(JSON.stringify({code:200,message:'',data:{name:'zhangsan',age:18,sex:'man'}}))
        }else{
            resp.write(JSON.stringify({code:404,message:'not found'}))
        }
    }else{
        resp.write(JSON.stringify({code:400,message:'not support this method'}))
    }
    resp.end();
}

const SERVER_PORT = 9420

app.listen(SERVER_PORT,() => {
    console.log(`service started on port: ${SERVER_PORT}` )
})